import 'package:flutter/material.dart';

class CounterWidget extends StatefulWidget {

  final int initValue;

  const CounterWidget({Key key, this.initValue:0}) : super(key: key);

  @override
  _CounterWidgetState createState() => _CounterWidgetState();
}

class _CounterWidgetState extends State<CounterWidget> {

  int _counter;

  @override
  Widget build(BuildContext context) {
    print("build 被调用");
    return Scaffold(
      body: Center(
        child: FlatButton(
            onPressed: ()=>{
              setState(()=>++_counter)
            },
            child: Text('$_counter')
        )

      ),
    );
  }

  @override
  void initState() {
    super.initState();
    // 初始化状态
    _counter = widget.initValue;
    print("initState 被调用");
  }

  @override
  void didUpdateWidget(CounterWidget oldWidget) {
    super.didUpdateWidget(oldWidget);
    print("didUpdateWidget 被调用");
  }

  @override
  void deactivate() {
    super.deactivate();
    print("deactivate 被调用");
  }

  @override
  void dispose() {
    super.dispose();
    print("dispose 被调用");
  }

  @override
  void reassemble() {
    super.reassemble();
    print("reassemble 被调用");
  }

  @override
  void didChangeDependencies() {
    super.didChangeDependencies();
    print("didChangeDependencies 被调用");
  }

}
